@extends('admin.common.base-master')

@section('html-head')
    <link href="{{url('css/admin/pagenum.css')}}" rel="stylesheet" />

    <link rel="stylesheet" href="{{url('css/admin/jquery-ui.css')}}">
    <script type="text/javascript" src="{{url('css/admin/jquery-ui.min.js')}}"></script>
    <link href="{{url('js/lib/jquery-ui-timepicker-addon.css')}}" type="text/css" />
    <script src="{{url('js/lib/jquery-ui-timepicker-addon.js')}}" type="text/javascript"></script>
    <script src="{{url('js/lib/jquery.ui.datepicker-zh-CN.js')}}" type="text/javascript"></script>
    <script src="{{url('js/lib/jquery-ui-timepicker-zh-CN.js')}}" type="text/javascript"></script>
    <style>
        .sx{padding: 10px}
        .sx-btn{width: 64px;height: 30px;background-color: #4dbcd3;color: #fff;border: #4dbcd3;border-radius: 7%;}
        .sx-btn-excel{width: 128px;height: 30px;background-color: #4dbcd3;color: #fff;border: #4dbcd3;border-radius: 7%;}
    </style>
@endsection

@section('html-body')
    <!-- content start -->
    <div id="content">
        <!-- cur-position start -->
        <div id="cur-position">
            <span class="tit">当前位置：</span>
            <a href="#">订单管理</a>
            <em></em>
            <a href="#">订单列表</a>
        </div>
        <!-- cur-position end -->
        @include('admin.common.order-header')

        <div class="filter-box clearfix">
            <div class="fl" style="display: inline-flex">
                <div class="sx">
                    <span>订单号/收件人姓名/手机：</span>
                    <input type="text" class="gg-ipt" style="width: 130px;height: 26px" placeholder="订单号/姓名/手机" name="order_num" id="order_num" value="{{$orderNum}}">
                </div>

                <div class="sx">
                    <span>订单创建时间：</span>
                    <input class="gg-ipt" style="width: 130px;height: 26px" type="text" autocomplete="off" placeholder="开始时间" name="start_time" id="start_time" value="{{$startTime}}" />-
                    <input class="gg-ipt" style="width: 130px;height: 26px" type="text" autocomplete="off" placeholder="结束时间" name="end_time" id="end_time" value="{{$endTime}}" />
                </div>
                <div class="sx">
                    <span>订单状态：</span>
                    <select name="status" id="status" value="">
                        <option value="0"  selected >全部</option>
                        <option value="1" @if($status && $status == 1) selected @endif>待付款</option>
                        <option value="2" @if($status && $status == 2) selected @endif>待发货</option>
                        <option value="3" @if($status && $status == 3) selected @endif>待收货</option>
                        <option value="4" @if($status && $status == 4) selected @endif>待评价</option>
                        <option value="5" @if($status && $status == 5) selected @endif>已完成</option>
                        <option value="6" @if($status && $status == 6) selected @endif>已取消</option>
                        <option value="7" @if($status && $status == 7) selected @endif>售后</option>
                        <option value="8" @if($status && $status == 8) selected @endif>售后完成</option>
                    </select>
                </div>

                <div class="sx">
                    <button class="sx-btn" id="sx_btn">筛选</button>
                </div>
                <div class="sx">
                    <button class="sx-btn-excel" id="sx_btn_excel">导出excel</button>
                </div>
            </div>
        </div>


        <div class="table-box">
            <table class="table">
                <thead>
                <tr>
                    <th>ID</th>
                    <th>用户昵称</th>
                    <th>头像</th>
                    <th>收货人</th>
                    <th>订单编号</th>
                    <th>是否支付</th>
                    <th>支付时间</th>
                    <th>支付方式</th>
                    <th>订单状态</th>
                    <th>操作</th>
                </tr>
                </thead>
                <tbody>
                @if(count($orders) > 0)
                    @foreach($orders as $a)
                        <tr id="admin_{{$a->id}}">
                            <td>{{$a->id}}</td>
                            <td>{{$a->nickname}}</td>
                            <td><img src="{{$a->photo_url}}" alt="" width="40px"></td>
                            <td>{{$a->name}}</td>
                            <td>{{$a->order_num}}</td>
                            <td>
                                @if($a->is_pay == 0)
                                    <p style="color: red;">未支付</p>
                                @else
                                    <p style="color: #008200;">已支付</p>
                                @endif

                            </td>
                            <td>{{$a->pay_time}}</td>
                            <td>
                                @if($a->pay_type == 'wechat')
                                    微信
                                @else
                                    @if($a->pay_type == 'balance')
                                        余额
                                    @else
                                        未知
                                    @endif
                                @endif


                            </td>
                            <td>
                                @if($a->status == 0)
                                    <p  style="color:red;">未完成</p>
                                @elseif($a->status == 1)
                                    <p style="color:red;">待付款</p>
                                @elseif($a->status == 2)
                                    <p style="color: red;">待发货</p>
{{--                                    <a class="changeOrderStatus" data-id="{{$a->id}}" href="javascript:;"><p style="color: red;">待发货</p></a><br/>--}}
{{--                                        <a href="{{route('Admin.Home.writeShipInfo')}}?id={{$a->id}}">发货信息填写</a>--}}
                                @if(!is_null($a->express_time) && $a->express_time != '')
                                    <p>填写时间：{{$a->express_time}}</p>
                                @endif
                                        <a href="javascript:void(0);" id="order_{{$a->id}}" data-name="{{$a->name}}" onclick="upPop('{{$a->id}}','{{$a->phone}}','{{$a->express_num}}')">发货信息填写</a>
                                @elseif($a->status == 3)
                                    <p style="color:red;">待收货</p>
                                @elseif($a->status == 4)
                                    <p style="color:red;">待评价</p>
                                @elseif($a->status == 5)
                                    <p style="color:green;">完成</p>
                                @elseif($a->status == 6)
                                    <p style="color:orange;">取消订单</p>
                                @elseif($a->status == 7)
                                    <p style="color:red;">售后</p>
                                @elseif($a->status == 8)
                                    <p style="color:red;">售后完成</p>
                                @endif

                            </td>
                            <td>
                                <a class="color2" href="{{route('Admin.Home.ordersDetails')}}?id={{$a->id}}">查看详情</a>
                            </td>
                        </tr>
                    @endforeach
                @endif
                </tbody>
            </table>
            <?php echo $orders->appends(['order_num' => $orderNum,'start_time' => $startTime,'end_time' => $endTime])->render(); ?>
        </div>
    </div>

    <div class="upPop-box">
        <div class="backdrop"></div>
        <div id="upPop" class="info-pop tixian">
            <input type="hidden" name="id" id="orderId" value=""/>
            <a class="close" href="javascript:void(0);"></a>
            <h3>发货信息设置</h3>
            <div class="fill-list">
                <span class="fill-tit">收件人：</span>
                <input class="gg-ipt" type="text" readonly="readonly" id="name" value="" style="border: none;outline: none;"/>
            </div>

            <div class="fill-list">
                <span class="fill-tit">手机号:</span>
                <input class="gg-ipt" type="text" readonly="readonly" id="phone" value="" style="border: none;outline: none;"/>
            </div>

{{--            <div class="fill-list">--}}
{{--                <span class="fill-tit">邮政编码：</span>--}}
{{--                <input class="gg-ipt" type="text" readonly="readonly" id="postcode" value="" style="border: none;outline: none;"/>--}}
{{--            </div>--}}

{{--            <div class="fill-list">--}}
{{--                <span class="fill-tit">发货地址：</span>--}}
{{--                <input class="gg-ipt" type="text" readonly="readonly" id="Address" value="" style="width:200px;border: none;outline: none;"/>--}}
{{--            </div>--}}

            <div class="fill-list">
                <span class="fill-tit">发货公司：</span>
                <select name="express_id" id="express_id">
                    @if(count($thisExpress) > 0)
                        @foreach($thisExpress as $thisExpr)
                            <option value="{{$thisExpr->id}}" @if($thisExpr && $thisExpr->is_default == 1)selected @endif>{{$thisExpr->name}}</option>
                        @endforeach
                    @endif
                </select>
            </div>

            <div class="fill-list">
                <span class="fill-tit">配送单号：</span>
                <input class="gg-ipt" type="text" id="express_num" value="" />
            </div>

            <input type="hidden" name="id" id="classify_id" />
            <div class="fill-list">
                <span class="fill-tit">&nbsp;</span>
                <input class="fill-submit" type="button" id="subThisForm" value="保存草稿">
            </div>
            <div class="fill-list">
                <span class="fill-tit">&nbsp;</span>
                <input class="fill-submit" style="color: #FF0000" type="button" id="sendNow" value="确认发货">
            </div>
        </div>
    </div>
    <!-- content end -->
    <script>
        function upPop(obj1,obj3,obj6){
            $('#orderId').val(obj1);
            var name = $("#order_"+obj1).data("name");
            $('#name').val(name);
            $('#phone').val(obj3);
            // $('#postcode').val(obj4);
            // $('#Address').val(obj5);
            $('#express_num').val(obj6);
            $('.upPop-box').upPop();

        }

        $(function(){
            jQuery('#start_time').datetimepicker({
                timeFormat: "HH:mm:ss",
                dateFormat: "yy-mm-dd",
                beforeShow: function () {
                    setTimeout(
                            function () {
                                $('#ui-datepicker-div').css("z-index", 1000);
                            }, 100
                    );
                }
            });

            jQuery('#end_time').datetimepicker({
                timeFormat: "HH:mm:ss",
                dateFormat: "yy-mm-dd",
                beforeShow: function () {
                    setTimeout(
                            function () {
                                $('#ui-datepicker-div').css("z-index", 1000);
                            }, 100
                    );
                }
            });

            $('#sx_btn').click(function(){
                var orderNum  = $('#order_num').val();
                var startTime = $('#start_time').val();
                var endTime   = $('#end_time').val();
                var status    = $('#status option:selected').val();

                window.location.href = "{{route('Admin.Home.ordersList')}}?order_num="+orderNum+"&start_time="+startTime+"&end_time="+endTime+"&status="+status;
            });

            $('#sx_btn_excel').click(function(){
                var orderNum  = $('#order_num').val();
                var startTime = $('#start_time').val();
                var endTime   = $('#end_time').val();
                var status    = $('#status option:selected').val();

                window.location.href = "{{route('Admin.Home.downLoadExcel')}}?order_num="+orderNum+"&start_time="+startTime+"&end_time="+endTime+"&status="+status;
            });

            $(document).on('click', '#subThisForm', function () {
                var expressNum   = $('#express_num').val();
                var expressId    = $('#express_id option:selected').val();
                var id           = $('#orderId').val();

                $.ajax({
                    url: '{{route("Api.Admin.order.setShipInfo")}}',
                    type: 'post',
                    dataType: 'json',
                    data: {
                        express_num: expressNum,
                        express_id:expressId,
                        id:id
                    },
                    success: function (obj) {
                        if (obj.level == "success") {
                            noty({
                                text: obj.message, type: obj.level, timeout: 600,
                                callback: {
                                    afterClose:function(){
                                        window.location.reload();
                                    }
                                }
                            });
                        } else if (obj.level == "error") {
                            noty({text: obj.message, type: obj.level, timeout: 600});
                        }

                    },
                    error: function (obj) {
                        console.log(obj);
                    }
                });
            });

            {{--$(document).on('click', '.changeOrderStatus', function () {--}}
            {{--    var id   = $(this).attr('data-id');--}}

            {{--    $.ajax({--}}
            {{--        url: '{{route("Api.Admin.order.changeOrderStatus")}}',--}}
            {{--        type: 'post',--}}
            {{--        dataType: 'json',--}}
            {{--        data: {--}}
            {{--            id:id--}}
            {{--        },--}}
            {{--        success: function (obj) {--}}
            {{--            if (obj.level == "success") {--}}
            {{--                noty({--}}
            {{--                    text: obj.message, type: obj.level, timeout: 600,--}}
            {{--                    callback: {--}}
            {{--                        afterClose:function(){--}}
            {{--                            window.location.href = "{{route('Admin.Home.ordersList')}}";--}}
            {{--                        }--}}
            {{--                    }--}}
            {{--                });--}}
            {{--            } else if (obj.level == "error") {--}}
            {{--                noty({text: obj.message, type: obj.level, timeout: 600});--}}
            {{--            }--}}

            {{--        },--}}
            {{--        error: function (obj) {--}}
            {{--            console.log(obj);--}}
            {{--        }--}}
            {{--    });--}}
            {{--});--}}

            $(document).on('click', '#sendNow', function () {
                var expressNum   = $('#express_num').val();
                var expressId    = $('#express_id option:selected').val();
                var id           = $('#orderId').val();

                $.ajax({
                    url: '{{route("Api.Admin.order.setShipInfo")}}',
                    type: 'post',
                    dataType: 'json',
                    data: {
                        express_num: expressNum,
                        express_id:expressId,
                        id:id
                    },
                    success: function (obj) {
                        if (obj.level == "success") {
                            $.ajax({
                                url: '{{route("Api.Admin.order.changeOrderStatus")}}',
                                type: 'post',
                                dataType: 'json',
                                data: {
                                    id:id
                                },
                                success: function (obj) {
                                    if (obj.level == "success") {
                                        noty({
                                            text: obj.message, type: obj.level, timeout: 600,
                                            callback: {
                                                afterClose:function(){
                                                    window.location.reload();
                                                }
                                            }
                                        });
                                    } else if (obj.level == "error") {
                                        noty({text: obj.message, type: obj.level, timeout: 600});
                                    }

                                },
                                error: function (obj) {
                                    console.log(obj);
                                }
                            });
                            // noty({
                            //     text: obj.message, type: obj.level, timeout: 600,
                            //     callback: {
                            //         afterClose:function(){
                            //             window.location.reload();
                            //         }
                            //     }
                            // });
                        } else if (obj.level == "error") {
                            noty({text: obj.message, type: obj.level, timeout: 600});
                        }

                    },
                    error: function (obj) {
                        console.log(obj);
                    }
                });
                // var id   = $('#orderId').val();

                {{--$.ajax({--}}
                {{--    url: '{{route("Api.Admin.order.changeOrderStatus")}}',--}}
                {{--    type: 'post',--}}
                {{--    dataType: 'json',--}}
                {{--    data: {--}}
                {{--        id:id--}}
                {{--    },--}}
                {{--    success: function (obj) {--}}
                {{--        if (obj.level == "success") {--}}
                {{--            noty({--}}
                {{--                text: obj.message, type: obj.level, timeout: 600,--}}
                {{--                callback: {--}}
                {{--                    afterClose:function(){--}}
                {{--                        window.location.reload();--}}
                {{--                    }--}}
                {{--                }--}}
                {{--            });--}}
                {{--        } else if (obj.level == "error") {--}}
                {{--            noty({text: obj.message, type: obj.level, timeout: 600});--}}
                {{--        }--}}

                {{--    },--}}
                {{--    error: function (obj) {--}}
                {{--        console.log(obj);--}}
                {{--    }--}}
                {{--});--}}
            });
        });
    </script>

@endsection